<?
function sqlite_table_exists(&$sqlite, $table)
{
    $result = $sqlite->query("SELECT name FROM sqlite_master WHERE type='table' AND name='$table'");
    return $result->numRows() > 0;
}

function sanitize($input){
	return  sqlite_escape_string(html_entity_decode($input));
}

function result_to_array($result){
	while($row=$result->fetch(SQLITE_ASSOC)){
		foreach($row as $key=>$value){
			echo $key.': '.$value.'<br>';
		}
		echo '<br>';
	}
}

function is_valid_employee($db, $id){
	$id = sanitize($id);
	
	$result=@$db->query("select public_key from employees where status = \"ACTIVE\" AND id = ".$id);
	if($result){
		while($row=$result->fetch(SQLITE_ASSOC)){
			$key = $row['public_key'];
		}
	}
	
	return $key;
}
?>